import 'package:flutter_keep_book/core/extensions/map.dart';
import 'package:flutter_keep_book/core/network/http_url.dart';

import 'local_storage.dart';

class LocalStorageUrl {
  /// 用户协议
  static String get userAgreement =>
      LocalStorage.getString(LocalStorageKey.userAgreement) ??
      'https://cdn.ynengliang.com/static/agreement/%E5%85%83%E9%AD%94%E6%96%B9%E7%94%A8%E6%88%B7%E5%8D%8F%E8%AE%AE.html';
  static set userAgreement(String? value) {
    if (value != null && value.isNotEmpty) {
      LocalStorage.saveString(LocalStorageKey.userAgreement, value);
    } else {
      LocalStorage.remove(LocalStorageKey.userAgreement);
    }
  }

  /// 隐私政策
  static String get privacyPolicy =>
      LocalStorage.getString(LocalStorageKey.privacyPolicy) ??
      'https://cdn.ynengliang.com/static/agreement/%E5%85%83%E9%AD%94%E6%96%B9%E9%9A%90%E7%A7%81%E5%8D%8F%E8%AE%AE.html';
  static set privacyPolicy(String? value) {
    if (value != null && value.isNotEmpty) {
      LocalStorage.saveString(LocalStorageKey.privacyPolicy, value);
    } else {
      LocalStorage.remove(LocalStorageKey.privacyPolicy);
    }
  }

  /// 支付协议
  static String get paymentAgreement =>
      LocalStorage.getString(LocalStorageKey.paymentAgreement) ??
      'https://cdn.ynengliang.com/static/agreement/%E5%85%83%E9%AD%94%E6%96%B9%E8%B4%AD%E4%B9%B0%E5%8D%8F%E8%AE%AE.html';
  static set paymentAgreement(String? value) {
    if (value != null && value.isNotEmpty) {
      LocalStorage.saveString(LocalStorageKey.paymentAgreement, value);
    } else {
      LocalStorage.remove(LocalStorageKey.paymentAgreement);
    }
  }

  /// 运费规则
  static String get deliveryPriceRule =>
      LocalStorage.getString(
        LocalStorageKey.deliveryPriceRule,
      ) ??
      'https://cdn.ynengliang.com/static/agreement/%E8%BF%90%E8%B4%B9%E8%A7%84%E5%88%99.html';
  static set deliveryPriceRule(String? value) {
    if (value != null && value.isNotEmpty) {
      LocalStorage.saveString(LocalStorageKey.deliveryPriceRule, value);
    } else {
      LocalStorage.remove(LocalStorageKey.deliveryPriceRule);
    }
  }

  /// 魔盒玩法指引
  static String get rulesOfPlay =>
      LocalStorage.getString(LocalStorageKey.rulesOfPlay) ??
      'https://cdn.ynengliang.com/static/agreement/%E7%8E%A9%E6%B3%95%E8%A7%84%E5%88%99.html';
  static set rulesOfPlay(String? value) {
    if (value != null && value.isNotEmpty) {
      LocalStorage.saveString(LocalStorageKey.rulesOfPlay, value);
    } else {
      LocalStorage.remove(LocalStorageKey.rulesOfPlay);
    }
  }

  ///第三方共享信息清单
  static String get commonBill =>
      LocalStorage.getString(LocalStorageKey.commonBill) ??
      'https://cdn.ynengliang.com/static/agreement/%E7%AC%AC%E4%B8%89%E6%96%B9%E4%BF%A1%E6%81%AF%E5%85%B1%E4%BA%AB%E6%B8%85%E5%8D%95.html';
  static set commonBill(String? value) {
    if (value != null && value.isNotEmpty) {
      LocalStorage.saveString(LocalStorageKey.commonBill, value);
    } else {
      LocalStorage.remove(LocalStorageKey.commonBill);
    }
  }

  ///第三方SDK列表
  static String get boxSdkList =>
      LocalStorage.getString(LocalStorageKey.boxSdkList) ??
      'https://cdn.ynengliang.com/static/agreement/%E7%AC%AC%E4%B8%89%E6%96%B9SDK%E5%88%97%E8%A1%A8.html';
  static set boxSdkList(String? value) {
    if (value != null && value.isNotEmpty) {
      LocalStorage.saveString(LocalStorageKey.boxSdkList, value);
    } else {
      LocalStorage.remove(LocalStorageKey.boxSdkList);
    }
  }

  static Map<String, dynamic> goodsSourceHostname = {};

  /// 商品来源
  static String goodsSourceApi(String key) {
    return goodsSourceHostname.stringValue(key) ?? HttpUrl.baseUrl;
  }
}
